import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/model/cookstep_list_model.dart';
import 'package:flutter_douban/model/store_category_model.dart';
import 'package:flutter_douban/model/store_product_detail_model.dart';
import 'package:flutter_douban/tool_views/photo_ViewScreen.dart';
import 'package:flutter_douban/tool_views/router.dart';

class ProductTopCell extends StatefulWidget {
  final StoreProductDetailModel model;
  final StoreCategoryModel storeModel;
  const ProductTopCell({Key? key, required this.model,required this.storeModel}) : super(key: key);

  @override
  _ProductTopCellState createState() => _ProductTopCellState();
}

class _ProductTopCellState extends State<ProductTopCell> {
  @override
  Widget build(BuildContext context) {
    List list = [
      widget.storeModel.ti == null ? widget.storeModel.i : widget.storeModel.ti,
      "http:\/\/i1.douguo.net\/upload\/tuan\/b\/1\/5\/640_b155b13f1e45a83ac1544ef41a30b145.jpg",
      "http:\/\/i1.douguo.net\/upload\/tuan\/2\/4\/2\/640_24f7ab757c3153bf333007fe5fb2d562.jpg",
      "http:\/\/i1.douguo.net\/upload\/tuan\/6\/2\/e\/640_62d58703c7177fd3d8ae518bd843b34e.jpg",
      "http:\/\/i1.douguo.net\/upload\/tuan\/c\/2\/1\/640_c292bbfef319cf315aab016d24806861.jpg",
      "http:\/\/i1.douguo.net\/upload\/tuan\/4\/8\/7\/640_4832e7b7730c53e6a7853e8e67112847.jpg"
    ];
    // List list = [widget.storeModel.ti == null ? widget.storeModel.i : widget.storeModel.ti];
    List<CookStepListModel> _dataList = [];
    list.forEach((element) {
      /// 大图浏览模式需要数据
      _dataList.add(CookStepListModel('', element, 0, 0, '', ''));
    });
    return Container(
        color: Colors.white,
        child: Column(
          children: [
            Container(
              height: 375,
              width: MediaQuery.of(context).size.width,
              child: Swiper(
                itemCount: list.length,
                autoplay: true,
                itemBuilder: (BuildContext context, int index) {
                  return Image.network(
                    list[index],
                    fit: BoxFit.cover,
                  );
                },

                /// 横线样式
                pagination: SwiperPagination(
                  ///指示器显示的位置 Alignment.bottomCenter 底部中间
                  alignment: Alignment.bottomCenter,

                  /// 距离调整
                  margin: const EdgeInsets.only(bottom: 5),

                  /// 指示器构建
                  builder: DotSwiperPaginationBuilder(

                      /// 点之间的间隔
                      space: 4,

                      /// 没选中时的大小
                      size: 6,

                      /// 选中时的大小
                      activeSize: 8,

                      /// 没选中时的颜色
                      color: Colors.white,

                      ///选中时的颜色
                      activeColor: AppColors.yellow),
                ),
                onTap: (index) {
                  Navigator.of(context).push(new FadeRouter(
                      child: PhotoViewGalleryScreen(
                        index: index,
                        dataArr: _dataList,
                      ),
                      duration_ms: 500));
                },
              ),
            ),
            Container(
              alignment: Alignment.topLeft,
              margin: EdgeInsets.only(left: 20, right: 20, top: 15, bottom: 15),
              child: Text(widget.storeModel.t == null ? widget.storeModel.n! : widget.storeModel.t!,
                  style: TextStyle(
                      fontSize: 20,
                      color: AppColors.black,
                      fontWeight: FontWeight.bold)),
            ),
            Container(
              margin: EdgeInsets.only(left: 20, right: 20, top: 0, bottom: 15),
              alignment: Alignment.centerLeft,
              child: Text(widget.storeModel.des == null ? '暂无数据' : widget.storeModel.des!,
                  style: TextStyle(
                    fontSize: 16,
                    color: Colors.black54,
                  )),
            ),
            Container(
              margin: EdgeInsets.only(left: 20, right: 20, top: 0, bottom: 10),
              alignment: Alignment.centerLeft,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Text(
                    "¥" + widget.storeModel.p!,
                    style: TextStyle(
                        fontSize: 20,
                        color: AppColors.danger,
                        fontWeight: FontWeight.bold),
                  ),
                  SizedBox(
                    width: 15,
                  ),
                  Text(
                    "¥" + widget.storeModel.op!,
                    style: TextStyle(
                      fontSize: 16,
                      color: Colors.black45,
                      decoration: TextDecoration.lineThrough,
                      decorationColor: Colors.black45,
                    ),
                  ),
                  SizedBox(
                    width: 15,
                  ),
                  Container(
                    height: 18,
                    width: 32,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      color: Color.fromRGBO(251, 235, 235, 1),
                      border: new Border.all(
                          color: Color.fromRGBO(251, 235, 235, 1), width: 1),
                      borderRadius: BorderRadius.circular(3),
                    ),
                    child: Text(
                      '包邮',
                      style: TextStyle(
                          fontSize: 11,
                          color: Color.fromRGBO(230, 87, 83, 1.0)),
                    ),
                  )
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(left: 20, right: 20, top: 0, bottom: 15),
              alignment: Alignment.centerLeft,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    widget.model.si!,
                    style: TextStyle(
                      fontSize: 14,
                      color: Colors.black45,
                      decorationColor: Colors.black45,
                    ),
                  ),
                  Text(
                    widget.model.add!,
                    style: TextStyle(
                      fontSize: 14,
                      color: Colors.black45,
                      decorationColor: Colors.black45,
                    ),
                  ),
                ],
              ),
            ),
            Container(
              width: MediaQuery.of(context).size.width,
              height: 10,
              color: AppColors.page,
            ),
            Container(
              margin: EdgeInsets.only(left: 20, right: 20, top: 0, bottom: 0),
              width: MediaQuery.of(context).size.width,
              height: 45,
              color: Colors.white,
              child: Row(
                // mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '促销',
                    style: TextStyle(
                      fontSize: 15,
                      color: Colors.black45,
                      decorationColor: Colors.black45,
                    ),
                  ),
                  SizedBox(
                    width: 15,
                  ),
                  Container(
                    height: 18,
                    width: 32,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      color: Color.fromRGBO(251, 235, 235, 1),
                      border: new Border.all(
                          color: Color.fromRGBO(251, 235, 235, 1), width: 1),
                      borderRadius: BorderRadius.circular(3),
                    ),
                    child: Text(
                      widget.model.atl![0]['t'],
                      style: TextStyle(
                          fontSize: 11,
                          color: Color.fromRGBO(230, 87, 83, 1.0)),
                    ),
                  ),
                  SizedBox(
                    width: 15,
                  ),
                  Text(
                    widget.model.atl![0]['c'],
                    style: TextStyle(
                      fontSize: 15,
                      color: Colors.black,
                    ),
                  ),
                ],
              ),
            ),
            Container(
              width: MediaQuery.of(context).size.width,
              height: 10,
              color: AppColors.page,
            ),
            Container(
              margin: EdgeInsets.only(left: 20, right: 20, top: 0, bottom: 0),
              width: MediaQuery.of(context).size.width,
              height: 45,
              color: Colors.white,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  RichText(
                    text: TextSpan(
                      text: '规格   ',
                      style: TextStyle(
                        fontSize: 15,
                        color: Colors.black45,
                        decorationColor: Colors.black45,
                      ),
                      children: [
                        TextSpan(
                          text: ' 已选 元气蛋30枚',
                          style: TextStyle(fontSize: 15, color: Colors.black),
                        ),
                      ],
                    ),
                  ),
                  SizedBox(
                    width: 15,
                  ),
                  Image.asset(
                    'assets/images/common/arrow_white_right@2x.png',
                    width: 20,
                    height: 20,
                    color: Colors.black38,
                  )
                ],
              ),
            ),
            Container(
              width: MediaQuery.of(context).size.width,
              height: 2,
              color: AppColors.page,
            ),
            Container(
              margin: EdgeInsets.only(left: 20, right: 20, top: 0, bottom: 0),
              width: MediaQuery.of(context).size.width,
              height: 45,
              color: Colors.white,
              child: InkWell(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      '配送至',
                      style: TextStyle(
                        fontSize: 15,
                        color: Colors.black45,
                        decorationColor: Colors.black45,
                      ),
                    ),
                    SizedBox(
                      width: 15,
                    ),
                    Image.asset(
                      'assets/images/common/arrow_white_right@2x.png',
                      width: 20,
                      height: 20,
                      color: Colors.black38,
                    )
                  ],
                ),
                onTap: () {},
              ),
            ),
            Container(
              width: MediaQuery.of(context).size.width,
              height: 10,
              color: AppColors.page,
            ),
          ],
        ));
  }
}
